using System;
using System.Collections.Generic;
using System.Text;

namespace v6502
{
    class RAM
    {
        private byte[] memory;

        public RAM(int size)
        {
            memory = new byte[size];
            clear();
        }

        public byte read(int address)
        {
            return memory[address];
        }

        public void write(int address, byte data)
        {
            memory[address] = data;
        }

        public void print(int startAddress, int length)
        {
            byte tmp;
            int currentLocation = startAddress;
            Console.WriteLine(
                "Dumping RAM: Start Location 0x"
                + String.Format("{0:x2}", (uint)System.Convert.ToUInt16(startAddress.ToString()))
                );

            for (int i = 0; i < length; i++)
            {
                tmp = read(currentLocation);
                currentLocation++;

                Console.Write(
                    String.Format("{0:x2}", (uint)System.Convert.ToUInt16(tmp.ToString()))
                    );

                if (i % 2 > 0)
                    Console.Write(" ");

                if ((i + 1) % 10 == 0)
                    Console.WriteLine();
            }
            Console.WriteLine();
        }

        public void clear()
        {
            for (int i = 0; i < memory.Length; i++)
                memory[i] = 0x00;
        }
    }
}
